﻿<UserControl x:Class="Notoric.View.Music.CWNotation.Controls.Note"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:vme="clr-namespace:Notoric.ViewModel.Elements.CWNotation;assembly=ViewModel" 
             xmlns:my="clr-namespace:Notoric.View.Music.CWNotation.Controls"
             DataContextChanged="UserControl_DataContextChanged"
             Loaded="UserControl_Loaded">
    <UserControl.Resources>
        <DataTemplate DataType="{x:Type vme:Accidental}">
            <Canvas>
                <my:Accidental DataContext="{Binding}" IsHitTestVisible="False"/>
            </Canvas>
        </DataTemplate>
    </UserControl.Resources>
    <Canvas>
        <my:NoteDragThumb x:Name="PART_HeadSymbol" FontFamily="MusicalSymbols" FontSize="{Binding EffectiveTypeSize, Mode=OneWay}"
                          Canvas.Left="{Binding HeadPosition, Mode=OneWay}" Canvas.Top="{Binding VerticalPosition, Mode=OneWay}"
                          Cursor="Hand" IsHitTestVisible="False" PreviewMouseLeftButtonDown="PART_HeadSymbol_PreviewMouseLeftButtonDown"
                          Text="w">
            <my:NoteDragThumb.Template>
                <ControlTemplate TargetType="{x:Type my:NoteDragThumb}">
                    <TextBlock x:Name="PART_Symbol" Text="{TemplateBinding Text}"/>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="PART_Symbol" Property="Foreground" Value="Blue"/>
                        </Trigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding Owner.IsSelected, Mode=OneWay}" Value="True"/>
                                <Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=FixedPage, AncestorLevel=1}}" Value="{x:Null}"/>
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.Setters>
                                <Setter TargetName="PART_Symbol" Property="Foreground" Value="Blue"/>
                            </MultiDataTrigger.Setters>
                        </MultiDataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </my:NoteDragThumb.Template>
            <my:NoteDragThumb.ContextMenu>
                <ContextMenu>
                    <MenuItem x:Name="menu_StemUp" Header="Stem Up" Click="menu_StemUp_Click"/>
                    <MenuItem x:Name="menu_StemDown" Header="Stem Down" Click="menu_StemDown_Click"/>
                    <Separator/>
                    <MenuItem Header="Articulation">
                        <MenuItem x:Name="menu_ArticulationLegato" Header="Legato" Click="menu_Articulation_Click"/>
                        <MenuItem x:Name="menu_ArticulationStaccato" Header="Staccato" Click="menu_Articulation_Click"/>
                        <MenuItem x:Name="menu_ArticulationStaccatissimo" Header="Staccatissimo" Click="menu_Articulation_Click"/>
                        <MenuItem x:Name="menu_ArticulationPortamento" Header="Portamento" Click="menu_Articulation_Click"/>
                        <MenuItem x:Name="menu_ArticulationTenuto" Header="Tenuto" Click="menu_Articulation_Click"/>
                    </MenuItem>
                    <Separator/>
                    <MenuItem Header="Accidental">
                        <MenuItem x:Name="menu_AccidentalDoubleSharp" Header="Double Sharp" Click="menu_Accidental_Click"/>
                        <MenuItem x:Name="menu_AccidentalSharp" Header="Sharp" Click="menu_Accidental_Click"/>
                        <MenuItem x:Name="menu_AccidentalNeutral" Header="Neutral" Click="menu_Accidental_Click"/>
                        <MenuItem x:Name="menu_AccidentalDoubleNeutral" Header="Double Neutral" Click="menu_Accidental_Click"/>
                        <MenuItem x:Name="menu_AccidentalFlat" Header="Flat" Click="menu_Accidental_Click"/>
                        <MenuItem x:Name="menu_AccidentalDoubleFlat" Header="Double Flat" Click="menu_Accidental_Click"/>
                    </MenuItem>
                </ContextMenu>
            </my:NoteDragThumb.ContextMenu>
        </my:NoteDragThumb>
        <Control x:Name="PART_DotsPosition" Visibility="Hidden" IsHitTestVisible="False"/>
        <ContentPresenter Content="{Binding Accidental, Mode=OneWay}" IsHitTestVisible="False"/>
        <ItemsControl ItemsSource="{Binding Owner.AugmentationDots, Mode=OneWay}" IsHitTestVisible="False">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas Background="Transparent"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate DataType="{x:Type vme:AugmentationDot}">
                    <Canvas>
                        <TextBlock Text="." Canvas.Left="{Binding Position, Mode=OneWay}" FontFamily="MusicalSymbols" 
                                   FontSize="{Binding Mode=OneWay, Path=DataContext.EffectiveTypeSize, RelativeSource={RelativeSource FindAncestor, AncestorType=my:Note, AncestorLevel=1}}"
                                   Canvas.Top="{Binding ElementName=PART_DotsPosition, Path=Margin.Top, Mode=OneWay}" />
                    </Canvas>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Canvas>
</UserControl>
